package cn.yhjz.admin.biz.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.admin.biz.entity.BizProduct;
import cn.yhjz.admin.biz.vo.BizProductVo;
import cn.yhjz.admin.biz.mapper.BizProductMapper;
import cn.yhjz.admin.biz.service.BizProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class BizProductServiceImpl implements BizProductService {

    @Autowired
    private BizProductMapper bizProductMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, BizProduct bizProduct) {
        Pager pager = new Pager();
        Long count = bizProductMapper.getPageCount(bizProduct);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<BizProductVo> records = bizProductMapper.getPage(pageOffset, pageSize, bizProduct);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalCount(count);
        return pager;
    }

    @Override
    public BizProduct insert(BizProduct bizProduct) {
        int res = bizProductMapper.insert(bizProduct);
        if (res > 0) {
            return bizProduct;
        } else {
            return null;
        }
    }

    @Override
    public List<BizProductVo> select(BizProduct bizProduct) {
        return bizProductMapper.select(bizProduct);
    }

    @Override
    public BizProductVo selectById(Long id) {
        return bizProductMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return bizProductMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(BizProduct bizProduct) {
        return bizProductMapper.updateByIdWithNull(bizProduct);
    }

    @Override
    public int updateById(BizProduct bizProduct) {
        return bizProductMapper.updateById(bizProduct);
    }

    @Override
    public int update(BizProduct entity, BizProduct param) {
        return bizProductMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(BizProduct entity, BizProduct param) {
        return bizProductMapper.updateWithNull(entity, param);
    }
}
